package 动态规划.股票买卖问题;

/**
 * @author: yangwk
 * @date: 2023/8/14
 * @description:
 **/
public class 固定资金买卖 {
    public static void main(String[] args) {
        System.out.println(maxProfit(10000, new int[]{
                5, 1, 2, 3, 5, 3, 3, 1, 2, 2
        }));
    }

    public static Double maxProfit(int totalBalance, int[] prices) {
        int left = 0;
        double totalCash = totalBalance;
        while (left < prices.length) {
            int minPrice = prices[left];
            int right = left + 1;
            while (right < prices.length && prices[right - 1] < prices[right]) {
                right++;
            }
            if (prices[right - 1] > minPrice) {
                totalCash = totalCash / minPrice * (prices[right - 1]);
            }
            left = right;
        }
        return totalCash - totalBalance;
    }
}
